package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelCommentQuery;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import cn.wolfcode.trip.base.util.JSONResult;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/*
* 游记评论接口
*
*
* */
@RestController
@RequestMapping("travelComments")
public class TravelCommentController {
    @Autowired
    private ITravelCommentService travelCommentService;

    //保存游记评论到数据库
    @PostMapping
    public Object saveTravelComment(TravelComment travelComment){
        //保存游记评论时后台自动保存userId字段(表示谁发表的评论)为当前登录用户的id
        User user = UserContext.getUserAttribute();
        travelComment.setUser(user);
        travelCommentService.save(travelComment);
        return new JSONResult();
    }

    //根据travelId查询关于这篇游记的所用评论
    @GetMapping("{travelId}")
    public PageInfo<TravelComment> list( TravelCommentQuery qo){
        PageInfo<TravelComment> info = travelCommentService.query(qo);
        return info;
    }


}
